Load in Packages used in the analysis

Read in Data

This is the SDR 2023 Data

sdr_data <- read_csv(here("data/SDR-2023-Data.csv"))

Clean column names of our dataframe

sdr_data <- sdr_data %>%
  clean_names()

SDG 6 World Map

Create a dataframe named world and select columns “name_long, iso_a3, and geometry”

world <- ne_countries(scale = "medium", returnclass = "sf")
world <- world %>% 
  select(name_long, iso_a3, geometry)

Change column names in both dataframes for the ISO3 Codes to match eachother and join the dataframes using leftjoin

colnames(sdr_data)[which(colnames(sdr_data) == "country_code_iso3")] <- "iso_a3"
sdr_data_world_joined <- left_join(sdr_data, world, by = "iso_a3")

Check the class of the dataframe and change the class to an sf dataframe

class(sdr_data_world_joined)
## [1] "spec_tbl_df" "tbl_df"      "tbl"         "data.frame"
sdr_data_world_joined <- st_as_sf(sdr_data_world_joined)
class(sdr_data_world_joined)
## [1] "sf"          "spec_tbl_df" "tbl_df"      "tbl"         "data.frame"

Now we specify a coordinate reference system to WGS84, which stands for World Geodetic System 1984

sdr_data_world_joined <- st_transform(sdr_data_world_joined, "+proj=longlat +datum=WGS84")
mytext <- paste(
    "Country: ", sdr_data_world_joined$country,"<br/>", 
    "Goal 6 Score: ", round(sdr_data_world_joined$goal_6_score, 2), 
    sep="") %>%
  lapply(htmltools::HTML)

leaflet(sdr_data_world_joined) %>% 
  addTiles()  %>% 
  setView( lat=10, lng=0 , zoom=2) %>%
  addPolygons(stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5, color = ~colorQuantile("YlOrRd", goal_6_score)(goal_6_score), label = mytext)

Mean SDG 6 Score by Region

Create a bar graph showing the mean SDG 6 Score by Region

mean_goal_6_scores <- sdr_data %>% 
  group_by(regions_used_for_the_sdr) %>% 
  summarize(mean_goal_6_score=mean(goal_6_score, na.rm = TRUE))
geom_bar <- ggplot(mean_goal_6_scores, aes(x= mean_goal_6_score, y = reorder(regions_used_for_the_sdr, mean_goal_6_score))) +
  geom_bar(stat = "identity") +
  theme_minimal() +
    labs (x = "Mean Clean Water and Sanitation Score",
        y = "")

ggplotly(geom_bar)

SDG 6 Score by Country in East & South Asia

Filter the data to East & South Asia. Create a bar chart for SDG 6 Clean Water and Sanitation. Then, reorder by country and add labels.

esa_sdr_data <- sdr_data %>% 
  filter(regions_used_for_the_sdr == "East & South Asia")
geom_bar <- ggplot(esa_sdr_data, aes(x= goal_6_score, y = reorder(country, goal_6_score))) +
  geom_bar(stat = "identity") +
  theme_minimal() +
    labs (x = "Clean Water and Sanitation",
        y = "")

ggplotly(geom_bar)
scatter_plot <- ggplot(esa_sdr_data, aes(x = goal_1_score, 
                     y = goal_6_score,
                     color = country)) +
  geom_point() +
  geom_smooth() +
  stat_cor() +
  theme_minimal() +
  labs (x = "SDG 1 Score",
        y = "SDG 6 Score",
        color = "Country")

ggplotly(scatter_plot)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'